#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 110, INF = 0x3f3f3f3f;

int n, m;
int w[N][N], level[N];
int dist[N];
bool st[N];

int dijkstra(int low, int up) {
    memset(dist, 0x3f, sizeof dist);
    memset(st, 0, sizeof st);
    
    dist[0] = 0;
    for (int i = 0; i < n; ++ i) {
        int t = -1;
        for (int j = 0; j <= n; ++ j)
            if (!st[j] && (t == -1 || dist[t] > dist[j]))
                t = j;
                
        st[t] = true;
        
        for (int j = 1; j <= n; ++ j)
            if (level[j] >= low && level[j] <= up)
                dist[j] = min(dist[j], dist[t] + w[t][j]);
    }
    
    return dist[1];
}

int main() {
    cin >> m >> n;
    
    memset(w, 0x3f, sizeof w);
    for (int i = 1; i <= n; ++ i) w[i][i] = 0;
    
    for (int i = 1; i <= n; ++ i) {
        int price, cnt;
        scanf("%d%d%d", &price, &level[i], &cnt);
        w[0][i] = min(w[0][i], price);
        
        while (cnt -- ) {
            int id, cost;
            scanf("%d%d", &id, &cost);
            w[id][i] = min(w[id][i], cost);
        }
    }
    
    int ans = INF;
    for (int i = level[1] - m; i <= level[1]; ++ i) ans = min(ans, dijkstra(i, i + m));
    
    cout << ans << endl;
    
    return 0;
}